/******************************************************************************
** 
** File name:	UTEST_14.c
**	
** Description:	RTOS Ver.3 Unit Tests. FAST Interrupt processing. Checking 
**				configuration and minimum overhead for the RTOS FAST interrupt
**				processing.
**
** RTOS API Services to be checked:
**
**		- RTOS_DECLARE_FAST_ISR()
**		- User defined assembler interrupt handler (see UTEST.S)
**
** Notes:		PASSED
**
*******************************************************************************
**
** Change history:
**	
** 10/09/2012 -AK- 	File created
**
******************************************************************************/
#include <avr/io.h>
#include <avr/interrupt.h>

#ifndef UTEST_14
#	error "UTEST_14 must be defined as -D$(Configuration) compiler option"
#endif

#include "UTEST_RES.h"

RTOS_DECLARE_FAST_ISR( USER_TIMER_2_VECTOR, FastIsrHandler );

UTST_TIMER_t	usr_tmr_2 = 
{
	&(USER_TIMER_2),
	10000,
	LEVEL_HIGH,
	STATE_RUN
};


/******************************************************************************
**	UNIT TEST INTERRUPT FUNCTION[s]
******************************************************************************/

// Assembler FastIsrHandlerASM() routine is described in UTEST.S

/******************************************************************************
**	UNIT TEST TASK FUNCTION[s]
******************************************************************************/
/*
** RTOS Task #0 - Stack checking task
*/
RTOS_TASK_FUNC(tsk0)
{
	while (1)
	{	
		RTOS_DebugPrint("[T0] Checking stacks consistency");

		RTOS_StackCheck(tsk0);
		RTOS_StackCheck(tsk1);
		RTOS_StackCheck(tsk2);
		RTOS_StackCheck(tsk3);
		
		RTOS_TaskSuspend(&tsk0PID);
		
	}
}

/*
** RTOS Task #1
*/
RTOS_TASK_FUNC(tsk1)
{
    utst_init_timer(&usr_tmr_2);
	
	RTOS_DebugPrint("\t[T1] Started");
	while(1)
	{
		RTOS_DebugPrint("\t[T1] RTOS_TaskYield() ...");
		RTOS_TaskYield();	
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

/*
** RTOS Task #2 
*/
RTOS_TASK_FUNC(tsk2)
{
	RTOS_DebugPrint("\t\t[T2] Started");
	while(1)
	{
		RTOS_DebugPrint("\t\t[T2] RTOS_TaskYield() ...");
		RTOS_TaskYield();	
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

/*
** RTOS Task #3 
*/
RTOS_TASK_FUNC(tsk3)
{
	RTOS_DebugPrint("\t\t\t[T3] Started");
	while(1)
	{
		RTOS_DebugPrint("\t\t\t[T3] RTOS_TaskYield() ...");
		RTOS_TaskYield();	
		RTOS_TaskResume(&tsk0PID);		// check stack consistency
	}
}

